#pragma once

class cTimer
{
public:
	cTimer();
	~cTimer();

	long long GetNowTime();
private:

#ifdef _WIN32
	void* m_TicksPerSecond; // LARGE_INTEGER*
#endif
} ;




/** Utility class that is used RAII-like, to measure an interval between its creation and its destruction:
The elapsed time is output only if it's longer than MinInterval.
*/
class cStopWatch
{
protected:
	clock_t m_BeginClock;
	clock_t m_MinInterval;
	AString m_Name;
	
public:
	cStopWatch(clock_t a_MinInterval, const char * a_Fmt, ...) :
		m_BeginClock(clock()),
		m_MinInterval(a_MinInterval)
	{
		va_list args;
		va_start(args, a_Fmt);
		AppendVPrintf(m_Name, a_Fmt, args);
		va_end(args);
	}
	
	~cStopWatch()
	{
		clock_t Elapsed = clock() - m_BeginClock;
		if (Elapsed > m_MinInterval)
		{
			LOG("%s took %d ticks (%.02f sec)", m_Name.c_str(), Elapsed, (double)Elapsed / CLOCKS_PER_SEC);
		}
	}
} ;





#define STOPWATCH(interval,fmt,...) \
	cStopWatch MACRO_CONCAT(sw, __COUNTER__)(interval, fmt, __VA_ARGS__);





#ifdef _DEBUG
	#define STOPWATCHD STOPWATCH
#else
	#define STOPWATCHD(...)
#endif  // _DEBUG




